/**
 * Copyright © 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.cms.site.entity;


import com.jeeplus.cms.support.validation.PatternExtend;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.modules.cms.theme.entity.CmsThemes;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.URL;

import javax.validation.constraints.NotNull;


/**
 * 网站Entity
 *
 * @author Sawyer
 * @version 2020-11-21
 */
@Getter
@Setter
@ToString
public class CmsSite extends DataEntity<CmsSite> {

    private static final long serialVersionUID = 1L;

    @Length(min = 2, max = 32, message = "网站名称长度必须介于 2 和 32 之间")
    @ExcelField(title = "网站名称", align = 2, sort = 1)
    private String name;

    @Length(min = 2, max = 32, message = "网站标题长度必须介于 2 和 32 之间")
    @ExcelField(title = "网站标题", align = 2, sort = 2)
    private String title;

    @ExcelField(title = "网站副主题", align = 2, sort = 3)
    @PatternExtend(regexp = "^.{1,60}$", message = "网站副主题最大长度不能超过60")
    private String subtitle;

    @ExcelField(title = "网站Logo", align = 2, sort = 4)
    @PatternExtend(regexp = "^.{5,1024}$", message = "网站Logo路径最大长度不能超过1024")
    private String logo;

    @URL(message = "网站域名必须为合法网址")
    @ExcelField(title = "网站域名", align = 2, sort = 5)
    private String domain;

    @Length(min = 10, max = 200, message = "网站简述长度必须介于 10 和 250 之间")
    @ExcelField(title = "网站简述", align = 2, sort = 6)
    private String description;

    @Length(min = 3, max = 200, message = "关键字长度必须介于 3 和 200 之间")
    @ExcelField(title = "关键字", align = 2, sort = 7)
    private String keywords;

    @Length(min = 10, max = 200, message = "版权信息长度必须介于 10 和 200 之间")
    @ExcelField(title = "版权信息", align = 2, sort = 8)
    private String copyright;

    @ExcelField(title = "自定义首页视图", align = 2, sort = 9)
    @PatternExtend(regexp = "^\\w{1,64}$", message = "自定义首页视图应为1-64个字符")
    private String customIndexView;

    @PatternExtend(regexp = "(^([0-9]{3,4}-)?[0-9]{7,8}$)|(^1[0-9]{10}$)", required = true, message = "联系方式无效")
    @ExcelField(title = "电话", align = 2, sort = 10)
    private String phone;

    @ExcelField(title = "传真", align = 2, sort = 11)
    private String fax;

    @ExcelField(title = "QQ", align = 2, sort = 12)
    @PatternExtend(regexp = "^\\d{1,30}$", message = "QQ无效")
    private String qq;

    @ExcelField(title = "微信", align = 2, sort = 13)
    @PatternExtend(regexp = "^\\w{1,30}$", message = "微信号无效")
    private String wechat;

    @ExcelField(title = "微信二维码", align = 2, sort = 14)
    @PatternExtend(regexp = "^.{5,1024}$", message = "微信二维码路径最大长度不能超过1024")
    private String wechatQrcode;

    @PatternExtend(regexp = "^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$", message = "邮箱无效")
    @ExcelField(title = "Email", align = 2, sort = 15)
    private String email;

    @Length(min = 3, max = 200, message = "地址长度必须介于 3 和 200 之间")
    @ExcelField(title = "地址", align = 2, sort = 16)
    private String address;

    @ExcelField(title = "经度", align = 2, sort = 17)
    @PatternExtend(regexp = "^[0-9.]{1,20}$", message = "经度无效")
    private String longitude;

    @ExcelField(title = "纬度", align = 2, sort = 18)
    @PatternExtend(regexp = "^[0-9.]{1,20}$", message = "纬度无效")
    private String latitude;

    @ExcelField(title = "首页点击数", align = 2, sort = 19)
    private Integer homeHits;

    /**
     * 网站主题
     */
    @NotNull(message = "关联主题不能为空")
    private CmsThemes theme;

    /**
     * 排序
     */
    private Integer sort;

    /**
     * 版本号，主要用于控制静态资源
     */
    @PatternExtend(regexp = "^\\d+(.\\d+){0,2}$", message = "版本号无效", required = true)
    private String siteVersion;

    public CmsSite() {
        super();
        this.setIdType(IDTYPE_AUTO);
    }

    public CmsSite(String id) {
        super(id);
    }

    /**
     * 初始化数据
     */
    public void init() {
        this.setHomeHits(0);
    }
}
